﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using online_magazine1.Models;

namespace online_magazine1.Controllers
{
    public class MagazineController : Controller
    {
        //
        // GET: /Magazine/
        MagazineEntities magDB = new MagazineEntities();
        private static string fileUrl = "";

        public ActionResult Index()
        {
            var themes = magDB.Themes.ToList();
            return View(themes);
        }

        public ActionResult Browse(string theme)
        {
            var th = magDB.Themes.Include("Articles").Single(t => t.ThemeName == theme);
            return View(th);
        }

        public ActionResult Details(int id)
        {
            Article article = magDB.Articles.Find(id);
            fileUrl = article.FileUrl;
            return View(article);
        }

        public ActionResult Download()
        {
            return File(fileUrl, "application/msword");
        }

    }
}
